/**
 * Created by Administrator on 2017/3/21.
 */
import React, { Component, Fragment } from 'react';
import { Form, Input, DatePicker, message, Button, Tabs, InputNumber, Radio, Select } from 'antd';
import {connect} from 'dva';
import Map from 'ol/Map';
import View from 'ol/View';
import TileLayer from 'ol/layer/Tile';
import XYZ from 'ol/source/XYZ';
import { Vector } from 'ol/layer';
import { Vector as VectorSource } from 'ol/source';
import Feature from 'ol/Feature';
import { Icon, Stroke, Style } from 'ol/style';
import Point from 'ol/geom/Point';
import { fromLonLat, toLonLat } from 'ol/proj';

import liuliang from './../../images/shuang.png';
import yali from './../../images/yali_blue.png';
import axios from 'axios';
import GeoJSON from 'ol/format/GeoJSON';
import setting from '../ValveFlowMeterSIte/setting.json';
const { TabPane } = Tabs;
const Option = Select.Option;
import styles from '../ValveFlowMeterSIte/index.less';
import find from 'lodash/find';
const FormItem = Form.Item;
class AddPoliciesForm extends Component {
  constructor(props) {
    super(props);
    this.state = {
      all_vendors:[],
      all_protocols:[],
    };
  }
  componentDidMount() {

  }
  render() {
    const formItemLayoutWithLabel = {
      labelCol: {
        xs: {span: 24},
        sm: {span: 7},
      },
      wrapperCol: {
        xs: {span: 24},
        sm: {span: 17},
      }
    };
    console.log(this.state.point)
    const {getFieldDecorator} = this.props.form;
    return (
      <div>
        <Form onSubmit={this.handleSubmit}>
            <FormItem
              {...formItemLayoutWithLabel}
              label={(
                <span>
                传感器类型
            </span>
              )}
            >
              {getFieldDecorator('type', {
                rules: [{ required: true, message: '请输入压力传感器量程' }],
                initialValue:this.props.type
              })(
                <Select disabled={true}>
                  <Option value={'CURRENT'}>电流类型</Option>
                  <Option value={'VOLTAGE'}>电压类型</Option>
                </Select>
              )}
            </FormItem>
            <FormItem
              {...formItemLayoutWithLabel}
              label={(
                <span>
               压力传感器量程(MPa)
            </span>
              )}
            >
              {getFieldDecorator('range', {
                initialValue: this.props.range,
                rules: [{ required: true, message: '请输入压力传感器量程' }],
              })(
                <InputNumber min={0} step={0.01}  style={{width:'100%'}}/>
              )}
            </FormItem>
          <FormItem
            {...formItemLayoutWithLabel}
            label={(
              <span>
               波动值(MPa)
            </span>
            )}
          >
            {getFieldDecorator('wave', {
              initialValue: this.props.wave,
              rules: [{ required: true, message: '请输入压力传感器量程' }],
            })(
              <InputNumber min={0}  step={0.01} style={{width:'100%'}}/>
            )}
          </FormItem>
          <FormItem
            {...formItemLayoutWithLabel}
            label={(
              <span>
               设备状态上传间隔(秒)
            </span>
            )}
          >
            {getFieldDecorator('state_interval', {
              initialValue: this.props.state_interval,
              rules: [{ required: true, message: '请输入设备状态上传间隔' }],
            })(
              <InputNumber min={0}  style={{width:'100%'}}/>
            )}
          </FormItem>
          <FormItem
            {...formItemLayoutWithLabel}
            label={(
              <span>
               数据采集上传间隔(秒)
            </span>
            )}
          >
            {getFieldDecorator('record_interval', {
              initialValue: this.props.record_interval,
              rules: [{ required: true, message: '请输入设备状态上传间隔' }],
            })(
              <InputNumber min={0}  style={{width:'100%'}}/>
            )}
          </FormItem>
          {
            (this.props.template===40||this.props.template===43)&&
            <FormItem
              {...formItemLayoutWithLabel}
              label={(
                <span>
               泄压微电机控制延时(秒)
            </span>
              )}
            >
              {getFieldDecorator('delay', {
                initialValue: this.props.delay,
                rules: [{ required: true, message: '请输入泄压微电机控制延时' }],
              })(
                <InputNumber min={0}  style={{width:'100%'}}/>
              )}
            </FormItem>
          }
          {
            [{name:'P0',key:'p0'},{name:'P1',key:'p1'},{name:'P2',key:'p2'},{name:'P3',key:'p3'}].map((item,index)=>{
              return <FormItem
                {...formItemLayoutWithLabel}
                label={(
                  <span>
               {item.name}
            </span>
                )}
              >
                {getFieldDecorator(item.key, {
                  initialValue: this.props[item.key],
                  rules: [{ required: true, message: `请输入${item.name}` }],
                })(
                  <InputNumber  style={{width:'100%'}}/>
                )}
              </FormItem>
            })}

            <FormItem
              {...formItemLayoutWithLabel}
              label={''}
            >
              <Button style={{marginLeft:'162px'}} type={'primary'} block={true} onClick={()=>{
                window.open(`${window.location.origin}/tool`)
              }}>计算工具</Button>
            </FormItem>


        </Form>
      </div>
    );
  }
}

const AddPoliciesFormWrap = Form.create()(AddPoliciesForm);
export default connect()(AddPoliciesFormWrap);
